package com.itheima.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;


@Aspect
@Component
@Slf4j
public class TimeAspect {

    @Around("execution(* com.itheima.service.impl.*.*(..))")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        //1.开始时间计时
        long start = System.currentTimeMillis();

        //2.原来的方法 原封不动的执行
        Object result = pjp.proceed();

        //3.结束时间计时
        long end = System.currentTimeMillis();

        log.info("方法: {} 执行耗时: {} ms", pjp.getSignature().getName() , end-start);

        return result;
    }

}
